import Frame from "@/views/Frame";

// Home
import Home from "@/views/Home";
// Search
import Search from "@/views/Search";
// News
import News from "@/views/News";
// User Help
import User_help from "@/views/User_help";
// About Us
import About_us from "@/views/About_us";
// Shopping Cart
import ShoppingCart from "@/views/ShoppingCart";

// 注册
import Register from "@/views/Login/Register";
import MyOrder from "@/views/MyOrder";
import PersonalCenter from "@/views/PersonalCenter";
// 不存在路径
import NotFound from "@/views/NotFound";
// Navigate重定向组件
import { Navigate, Outlet } from "react-router-dom";

// 定义PrivateRoute组件，用于包裹需要权限验证的路由
const PrivateRoute = () => {
  const auth = localStorage.getItem("GY1"); // 获取用户认证状态
  return auth ? <Outlet /> : <Navigate to="/" replace />;
};

const routes = [
  {
    path: "/",
    element: <Navigate to="/home" />,
  },
  {
    path: "/",
    element: <Frame />,
    children: [
      {
        path: "home",
        element: <Home />,
      },
      {
        path: "search",
        element: <Search />,
      },
      {
        path: "news",
        element: <News />,
      },
      {
        path: "user_help",
        element: <User_help />,
      },
      {
        path: "about_us",
        element: <About_us />,
      },
      {
        path: "shoppingCart",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <ShoppingCart />,
          },
        ],
      },
      {
        path: "register",
        element: <Register />,
      },
      {
        path: "myOrder",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <MyOrder />,
          },
        ],
      },
      {
        path: "personalCenter",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <PersonalCenter />,
          },
        ],
      },
    ],
  },
  {
    path: "*",
    element: <NotFound />,
  },
];
export default routes;
